//  this library.
import 'package:hktk_app/ienum/my/asset_status_enum.dart';
import 'package:hktk_app/ienum/package/entity_type_enum.dart';
import 'package:hktk_app/ienum/package/order_type_enum.dart';

import 'package:hktk_app/model/package/package_model.dart';
import 'package:hktk_app/model/package/payment_model.dart';

/// 订单相关模型
class OrderModel {
  String? packageName;
  String? createdTime;
  String? modifyTime;
  String? createdBy;
  String? modifyBy;
  String? id;
  int? price;
  OrderTypeEnum? type;
  OrderStatusEnum? orderStatus;
  String? userId;
  String? expiredDate;
  String? remark;
  List<OrderDetailModel>? orderDetail;

  // 系统支付单
  PaymentModel? paymentModel;
  String? agentId;
  String? agentName;
  String? entityName;
  String? userName;
  String? createdByName;
  String? userMobile;
  int? money;
  dynamic extr;
  OrderDetailModel? oneDetail;
  String? orderSn;
  bool? havePay;
  double? priceDecimal;

  OrderModel({
    this.createdTime,
    this.modifyTime,
    this.createdBy,
    this.modifyBy,
    this.id,
    this.price,
    this.type,
    this.orderStatus,
    this.userId,
    this.expiredDate,
    this.remark,
    this.orderDetail,
    this.paymentModel,
    this.agentId,
    this.agentName,
    this.entityName,
    this.userName,
    this.createdByName,
    this.userMobile,
    this.money,
    this.extr,
    this.oneDetail,
    this.orderSn,
    this.havePay,
    this.priceDecimal,
    this.packageName
  });

  OrderModel.fromJson(Map<String, dynamic> json) {
    createdTime = json['createdTime'];
    modifyTime = json['modifyTime'];
    createdBy = json['createdBy'];
    modifyBy = json['modifyBy'];
    id = json['id'];
    price = json['price'];
    type =
    json['type'] != null ? OrderTypeEnum.getTypeEnum(json["type"]) : null;
    orderStatus = json['orderStatus'] != null
        ? OrderStatusEnum.getTypeEnum(json["orderStatus"])
        : null;
    userId = json['userId'];
    expiredDate = json['expiredDate'];
    remark = json['remark'];
    if (json['orderDetail'] != null) {
      orderDetail = <OrderDetailModel>[];
      json['orderDetail'].forEach((v) {
        orderDetail!.add(OrderDetailModel.fromJson(v));
      });
    }
    paymentModel = json['paymentModel'] != null
        ? PaymentModel.fromJson(json['paymentModel'])
        : null;
    agentId = json['agentId'];
    packageName = json['packageName'];
    agentName = json['agentName'];
    entityName = json['entityName'];
    userName = json['userName'];
    createdByName = json['createdByName'];
    userMobile = json['userMobile'];
    money = json['money'];
    extr = json['extr'];
    oneDetail = json['oneDetail'] != null
        ? OrderDetailModel.fromJson(json['oneDetail'])
        : null;
    orderSn = json['orderSn'];
    havePay = json['havePay'];
    priceDecimal = json['priceDecimal'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['createdTime'] = createdTime;
    data['packageName'] = packageName;
    data['modifyTime'] = modifyTime;
    data['createdBy'] = createdBy;
    data['modifyBy'] = modifyBy;
    data['id'] = id;
    data['price'] = price;
    if (type != null) {
      data['type'] = type!.name;
    }
    if (orderStatus != null) {
      data['orderStatus'] = orderStatus!.name;
    }
    data['userId'] = userId;
    data['expiredDate'] = expiredDate;
    data['remark'] = remark;
    if (orderDetail != null) {
      data['orderDetail'] = orderDetail!.map((v) => v.toJson()).toList();
    }
    if (paymentModel != null) {
      data['paymentModel'] = paymentModel!.toJson();
    }
    data['agentId'] = agentId;
    data['agentName'] = agentName;
    data['entityName'] = entityName;
    data['userName'] = userName;
    data['createdByName'] = createdByName;
    data['userMobile'] = userMobile;
    data['money'] = money;
    data['extr'] = extr;
    if (oneDetail != null) {
      data['oneDetail'] = oneDetail!.toJson();
    }
    data['orderSn'] = orderSn;
    data['havePay'] = havePay;
    data['priceDecimal'] = priceDecimal;
    return data;
  }
}

/// 订单详情相关模型
class OrderDetailModel {
  String? createdTime;
  String? modifyTime;
  String? createdBy;
  String? modifyBy;
  int? id;
  String? orderId;
  EntityTypeEnum? entityType;
  String? entityId;
  int? totalCount;
  int? userAssetId;
  PackageModel? assets;
  AssetsData? assetsData;

  OrderDetailModel({
    this.createdTime,
    this.modifyTime,
    this.createdBy,
    this.modifyBy,
    this.id,
    this.orderId,
    this.entityType,
    this.entityId,
    this.totalCount,
    this.userAssetId,
    this.assets,
    this.assetsData,
  });

  OrderDetailModel.fromJson(Map<String, dynamic> json) {
    createdTime = json['createdTime'];
    modifyTime = json['modifyTime'];
    createdBy = json['createdBy'];
    modifyBy = json['modifyBy'];
    id = json['id'];
    orderId = json['orderId'];
    entityType = json['entityType'] != null
        ? EntityTypeEnum.getTypeEnum(json["entityType"])
        : null;
    entityId = json['entityId'];
    totalCount = json['totalCount'];
    userAssetId = json['userAssetId'];
    assets =
    json['assets'] != null ? PackageModel.fromJson(json['assets']) : null;
    assetsData = json['assetsData'] != null
        ? AssetsData.fromJson(json['assetsData'])
        : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['createdTime'] = createdTime;
    data['modifyTime'] = modifyTime;
    data['createdBy'] = createdBy;
    data['modifyBy'] = modifyBy;
    data['id'] = id;
    data['orderId'] = orderId;
    if (entityType != null) {
      data['entityType'] = entityType!.name;
    }
    data['entityId'] = entityId;
    data['totalCount'] = totalCount;
    data['userAssetId'] = userAssetId;
    if (assets != null) {
      data['assets'] = assets!.toJson();
    }
    if (assetsData != null) {
      data['assetsData'] = assetsData!.toJson();
    }
    return data;
  }
}

class AssetsData {
  String? createdTime;
  String? modifyTime;
  String? createdBy;
  String? modifyBy;
  int? id;
  String? userId;
  EntityTypeEnum? assetType;
  String? assetMappingId;
  AssetStatusEnum? status;
  String? startTime;
  String? endTime;
  int? count;
  String? remark;
  String? lastOrderId;
  List<String>? orderIds;
  PackageModel? assets;

  AssetsData({
    this.createdTime,
    this.modifyTime,
    this.createdBy,
    this.modifyBy,
    this.id,
    this.userId,
    this.assetType,
    this.assetMappingId,
    this.status,
    this.startTime,
    this.endTime,
    this.count,
    this.remark,
    this.lastOrderId,
    this.orderIds,
    this.assets,
  });

  AssetsData.fromJson(Map<String, dynamic> json) {
    createdTime = json['createdTime'];
    modifyTime = json['modifyTime'];
    createdBy = json['createdBy'];
    modifyBy = json['modifyBy'];
    id = json['id'];
    userId = json['userId'];
    assetType = json['assetType'] != null
        ? EntityTypeEnum.getTypeEnum(json["assetType"])
        : null;
    assetMappingId = json['assetMappingId'];
    status = json['status'] != null
        ? AssetStatusEnum.getTypeEnum(json["status"])
        : null;
    startTime = json['startTime'];
    endTime = json['endTime'];
    count = json['count'];
    remark = json['remark'];
    lastOrderId = json['lastOrderId'];
    orderIds = json['orderIds'].cast<String>();
    assets =
    json['assets'] != null ? PackageModel.fromJson(json['assets']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['createdTime'] = createdTime;
    data['modifyTime'] = modifyTime;
    data['createdBy'] = createdBy;
    data['modifyBy'] = modifyBy;
    data['id'] = id;
    data['userId'] = userId;
    if (assetType != null) {
      data['assetType'] = assetType!.name;
    }
    data['assetMappingId'] = assetMappingId;
    if (status != null) {
      data['status'] = status!.name;
    }
    data['startTime'] = startTime;
    data['endTime'] = endTime;
    data['count'] = count;
    data['remark'] = remark;
    data['lastOrderId'] = lastOrderId;
    data['orderIds'] = orderIds;
    if (assets != null) {
      data['assets'] = assets!.toJson();
    }
    return data;
  }
}
